package com.alexgaoyh.MutiModule.Dubbo.RWSeperate.consumer.web.sysman.sysmanUser;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.MutiModule.common.twitter.IDGenerator.instance.IdWorkerInstance;
import com.alexgaoyh.MutiModule.Dubbo.RWSeperate.api.sysman.sysmanUser.read.ISysmanUserReadService;
import com.alexgaoyh.MutiModule.Dubbo.RWSeperate.api.sysman.sysmanUser.write.ISysmanUserWriteService;
import com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.sysman.sysmanUser.SysmanUser;
import com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.sysman.sysmanUser.SysmanUserExample;
import com.alibaba.dubbo.config.annotation.Reference;

/**
*
* dubbo 消费者
 * SysmanUser 模块 读接口
 * @author alexgaoyh
*
*/
@Controller
@RequestMapping(value="manager/sysmanUser")
public class SysmanUserController {

	@Reference(group="readService", interfaceName="com.alexgaoyh.MutiModule.Dubbo.RWSeperate.api.sysman.sysmanUser.read.ISysmanUserReadService")
	private ISysmanUserReadService sysmanUserReadService;
	
	@Reference(group="writeService", interfaceName="com.alexgaoyh.MutiModule.Dubbo.RWSeperate.api.sysman.sysmanUser.write.ISysmanUserWriteService")
	private ISysmanUserWriteService sysmanUserWriteService;
	
	@RequestMapping(value = "/index")
	public ModelAndView index(ModelAndView model, HttpServletRequest request) {
		SysmanUserExample example = new SysmanUserExample();
		example.setOrderByClause("id desc");
		List<SysmanUser> list = sysmanUserReadService.selectByExample(example);
		model.addObject("list", list);
		model.setViewName("manager/sysman/sysmanUser/index");
		return model;
	}
	
	@RequestMapping(value = "/save")
	public ModelAndView save(ModelAndView model, HttpServletRequest request) {
		SysmanUser record = new SysmanUser();
		record.setId(IdWorkerInstance.getId());
		record.setName(new Date().toString());
		record.setCreateTime(new Date());
		
		sysmanUserWriteService.insert(record);
		
		model.setViewName("redirect:index");
		return model;
	}

}
